package com.hatic.testdb;

import java.util.List;
import java.util.Map;

import org.jxstar.dao.DaoParam;

import com.hatic.money.PlanAuthBO;
import com.hatic.test.BaseTest;

/**
 * 补充基础数据类：
 * 根据投资计划数据创建项目数据
 * 注意：执行前需要配置数据连接到生产库中
 */
public class PlanDataTest extends BaseTest {

	public static void main(String[] args) {
		creatProject();
	}

	private static void creatProject(){
		PlanAuthBO auth = new PlanAuthBO();
		List<Map<String, String>> list = queryPlan(); 
		
		for(int i = 0, n = list.size(); i < n; i++){      
			Map<String, String> mpData = list.get(i);
			String planId = mpData.get("plan_id");
			String state = mpData.get("plan_status");
			
			if(!auth.projectCreate(planId, "system", "")){
				_log.showDebug("创建项目信息出错！");
				return;
			}
			
			//由于创建项目时把投资计划的状态改为“41”了，所以需要改回来
			retState(planId, state);
		}
	}
	
	private static void retState(String planId, String state) {
		String sql = "update money_plan set plan_status = ? where plan_id = ?";
		DaoParam param = _dao.createParam(sql);
		param.addStringValue(state);
		param.addStringValue(planId);
		_dao.update(param);
	}
	
	//取2011年结转到12年的投资计划，虚拟包不需要创建项目
	private static List<Map<String,String>> queryPlan() {
		String sql = "select plan_id, plan_status from money_plan where " +
				"plan_year = '2012' and is_turn = '1' and bao_type <> '1' " +
				"and plan_id not in (select plan_id from project_base)";
		DaoParam param = _dao.createParam(sql);
		
		return _dao.query(param);
	}
}
